local skel = fk.CreateSkill {
  name = "emo__yumo",
}

Fk:loadTranslationTable{
  ["emo__yumo"] = "予沫",
  [":emo__yumo"] = "出牌阶段限一次，你可以将手牌弃置至与一名其他角色相同，并令其摸等量张牌，然后若其手牌数：唯一最大，你令其对你选择的另一角色造成1点伤害；并列最大，你获得其他手牌最大角色各一张牌；不为最大，你摸两张牌且视为未发动本技能。",

  ["#emo__yumo"] = "你可以将手牌弃置至与一名其他角色相同，并令其摸等量张牌",
  ["#emo__yumo-damage"] = "予沫：选择一名角色，令%src对其造成1点伤害",
}

skel:addEffect("active", {
  anim_type = "support",
  prompt = "#emo__yumo",
  min_card_num = 1,
  target_num = 1,
  card_filter = function (self, player, to_select, selected)
    return not player:prohibitDiscard(to_select) and table.contains(player:getCardIds("h"), to_select)
  end,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected_cards > 0 and (player:getHandcardNum() - to_select:getHandcardNum()) == #selected_cards
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function (self, room, use)
    local player, to = use.from, use.tos[1]
    room:throwCard(use.cards, skel.name, player, player)
    if to.dead then return end
    to:drawCards(#use.cards, skel.name)
    if to.dead or player.dead then return end
    local max = 0
    for _, p in ipairs(room.alive_players) do
      max = math.max(max, p:getHandcardNum())
    end
    local maxPlayers = table.filter(room:getAlivePlayers(), function (p)
      return p:getHandcardNum() == max
    end)
    if #maxPlayers == 1 and maxPlayers[1] == to then
      local victim = room:askToChoosePlayers(player, {
        targets = room:getOtherPlayers(to), min_num = 1, max_num = 1, skill_name = skel.name, cancelable = false,
        prompt = "#emo__yumo-damage:" .. to.id , no_indicate = true
      })[1]
      if victim then
        room:doIndicate(to, {victim})
        room:damage { from = to, to = victim, damage = 1, skillName = skel.name }
      end
    elseif table.contains(maxPlayers, to) then
      table.removeOne(maxPlayers, to)
      for _, p in ipairs(maxPlayers) do
        if player.dead then break end
        if not p:isNude() then
          local cid = room:askToChooseCard(player, {target = p, flag = "he", skill_name = skel.name})
          room:obtainCard(player, cid, false, fk.ReasonPrey, player, skel.name)
        end
      end
    else
      player:drawCards(2, skel.name)
      player:setSkillUseHistory(skel.name, 0, Player.HistoryPhase)
    end
  end,
})

return skel
